const Mock = require('mockjs')

const users = {
        roles: ['admin'],
        introduction: 'I am a super administrator',
        avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
        name: 'Super Admin',
        date: '@date',
        avatar: "@image('200x100', '#50B347', '#FFF', 'Mock.js')", //参数：大小；背景；foreground（文字颜色）；文字 
        description: '@paragraph', // 描述
        ip: "@ip()", // ip地址
        email: "@email"
}

//返回一个函数
module.exports = function(app){
    if(process.env.Mock == "true"){// 对环境变量进行一个判断，方便我们替换真实接口
        //监听http请求
        app.get('/user/userinfo', function(req, res) {
            //将json文件传入Mock.mock 方法中，生成的数据返回给浏览器
            res.json(Mock.mock(users));
        });
    }
}
